package com.feng.extra;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

//所有的Bean定义信息将要被加载到容器 bean的实例还未被创建  在BeanFactoryPostProcessor之前调用
/*All regular bean definitions will have been loaded,
        * but no beans will have been instantiated yet.**/
@Component
public class MyBeanDefinitionRegistryPostprocessor implements BeanDefinitionRegistryPostProcessor {

    //该方法来自于BeanDefinitionRegistryPostProcessor 信息保存中心  以后BeanFactory就是按照BeanDefinitionRegistry里面保存的每一个bean定义信息创建bean实例
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

            System.out.println("我是BeanDefinitionRegistryPostProcessor---> postProcessBeanDefinitionRegistry Bean的数量"+ registry.getBeanDefinitionCount());

    }
    //该方法来自于BeanFactoryPostProcessor
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("我是BeanDefinitionRegistryPostProcessor---> postProcessBeanFactory Bean的数量"+ beanFactory.getBeanDefinitionCount());
    }
}
